from models.database import BaseModel


class DeviceRecord(BaseModel):
	"""
	设备借还记录模型类
	字段定义格式：(完整的SQL字段定义, 中文注释)
	"""
	TABLE_NAME = "device_records"
	
	id = ("id INTEGER PRIMARY KEY AUTOINCREMENT", "主键ID")
	machine_id = ("machine_id TEXT NOT NULL", "机器唯一标识(SN号)")
	serial_number = ("serial_number TEXT", "机器编号")
	owner_id = ("owner_id TEXT NOT NULL", "设备归属人")
	record_type = ("record_type TEXT NOT NULL CHECK(record_type IN ('借出', '借入'))", "记录类型")
	device_type = ("device_type TEXT NOT NULL", "设备类型")
	device_name = ("device_name TEXT NOT NULL", "设备名称")
	counterpart = ("counterpart TEXT NOT NULL", "对方信息")
	quantity = ("quantity INTEGER DEFAULT 1", "数量")
	borrow_date = ("borrow_date TEXT NOT NULL", "借出日期")
	expected_return_date = ("expected_return_date TEXT", "预计归还日期")
	actual_return_date = ("actual_return_date TEXT", "实际归还日期")
	status = ("status INTEGER DEFAULT 0", "归还状态（0未归还/1已归还）")
	created_at = ("created_at TEXT DEFAULT (datetime('now','localtime'))", "创建时间")
	updated_at = ("updated_at TEXT DEFAULT (datetime('now','localtime'))", "更新时间")
	notes = ("notes TEXT", "备注")
	
	@classmethod
	def get_field_comments(cls):
		"""获取字段注释字典"""
		return {
			field[0].split()[0]: field[1]  # 提取字段名作为key
			for field in cls.__dict__.values()
			if isinstance(field, tuple)
		}
